package com.cy.pj.goods.service;

import com.cy.pj.goods.dao.GoodsDao;
import com.cy.pj.goods.pojo.Goods;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class GoodsServiceImpl implements GoodsService {

//    获取到该类的运行日志信息
    private static final Logger log = LoggerFactory.getLogger(GoodsServiceImpl.class);

    @Autowired
    private GoodsDao goodsDao;

    @Override
    public List<Goods> findGoods(String name) {
        long t1 = System.currentTimeMillis();
        List<Goods> list = goodsDao.findGoods(name);
        long t2 = System.currentTimeMillis();




        log.info("查找所需时间:{} ms ", t2 - t1 );

        return list ;
    }

    @Override
    public Integer insertGoods(Goods goods) {
        long t1 = System.currentTimeMillis();
        int rows = goodsDao.insertGoods(goods);
        long t2 = System.currentTimeMillis();

        log.info("增加一条数据所需时间:{} ms ", t2 -t1 );

        return rows;
    }

    @Override
    public Integer updateGoods(Goods goods) {
        long t1 = System.currentTimeMillis();
        int rows = goodsDao.updateGoods(goods);
        long t2 = System.currentTimeMillis();

        log.info("更新一条数据的时间:{} ms ", t2 -t1 );

        return rows;
    }

    @Override
    public Integer deleteGoods(Integer id) {
        long t1 = System.currentTimeMillis();
        int rows = goodsDao.deleteGoods(id);
        long t2 = System.currentTimeMillis();

        log.info("删除一条数据的时间:{} ms ", t2 -t1 );

        return rows;
    }
}
